import { Component } from '@angular/core';
import { IonicPage, NavController, NavParams } from 'ionic-angular';
import {CheckstandPage} from "../checkstand/checkstand";
import {ROUTER} from "../../service/router.service";
import {APARTMENTAPISERVICE} from "../../api/apartment-api.service";
import {GoodModel} from "../../model/good.model";
import {LocalStorage} from "../../utils/localstorage.utils";
import {GOODS} from "../../api/goods-api";
import {USER} from "../../service/user.service";

/**
 * Generated class for the IntegralStoreOrderPage page.
 *
 * See http://ionicframework.com/docs/components/#navigation for more info
 * on Ionic pages and navigation.
 */
@IonicPage()
@Component({
  selector: 'page-integral-store-order',
  templateUrl: 'integral-store-order.html',
})
export class IntegralStoreOrderPage {
  good:GoodModel;
  data={
    layoutId:undefined
  };
  layoutList=[];

  moneyItems=[
    {
      name:'礼品名称',
      item:'100分'
    }
  ];

  constructor(public apartmentApi: APARTMENTAPISERVICE, public ls: LocalStorage,
              private ROUTER: ROUTER,
              private USER: USER,
              private GOODS:GOODS) {
  }

  ionViewDidLoad() {
    console.log('ionViewDidLoad IntegralStoreOrderPage');
    this.good = this.ls.getObject('good') as GoodModel;
    this.moneyItems[0].name = this.good.title;
    this.moneyItems[0].item = this.good.score;
    this.loadMyHouse()
  }

  goExchange() {
    let reqData = {
      totalMoney:0,
      houseId: this.data.layoutId,
      goodsId: this.good.id,
      source: 1,
      score:this.good.score
    }
    this.GOODS.purchaseScore(reqData,v=>{
      this.USER.toast("兑换成功，请去兑换记录中查看")
    })
    // this.ROUTER.go(ROUTER.CHECK);
  }
  loadMyHouse() {
    this.apartmentApi.getMyRentingHouse({}, (res:any)=> {
      this.layoutList = res;
      if(this.layoutList.length > 0){
        this.data.layoutId = this.layoutList[0].id
      }
    })
  }

}
